package hospital.cmn.controller;

import hospital.cmn.service.DictService;
import hospital.model.cmn.Dict;
import hospital.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author
 * @description:
 */
@Api(tags = "数据字典接口")
@RestController
@RequestMapping("/admin/cmn/dict")
//@CrossOrigin //允许跨域访问
public class DictController {
    @Autowired
    private DictService service;

    /**
     * @Author yang
     * @Description //TODO 导入数据字典接口
     * @Param
     * @return
     **/
    @PostMapping("importData")
    public Result importData(MultipartFile file){
        service.importData(file);
        return Result.ok();
    }
    /**
     * @Author yang
     * @Description //TODO 导出数据字典接口 数据的下载 HttpServletResponse用于文件上传或下载
     * @Para
     * @return
     **/
    @GetMapping("exportData")
    public void exportData(HttpServletResponse response){
        service.exportData(response);
    }
    /**
     * @Author yang
     * @Description //TODO 根据数据id查询，子数据列表
     * @Param
     * @return 
     **/
    @ApiOperation("根据数据id查询，子数据列表")
    @GetMapping("findChildData/{id}")
    public Result findChildData(@PathVariable Long id){
        List<Dict> list=service.findChildData(id);
        return Result.ok(list);
    }

    @ApiOperation("根据dictCode获取所有的下节节点")
    @GetMapping("findByDictCode/{dictCode}")
    public Result findByDictCode(@PathVariable("dictCode") String dictCode){
        //System.out.println(dictCode+"           ");

        List<Dict> list= service.findByDictCode(dictCode);
        return Result.ok(list);
    }

    //根据dictCode和Value 查询医院等级接口
    @ApiOperation("根据dictCode和Value 查询医院等级接口")
    @GetMapping("getDictName/{dictCode}/{value}")
    public String getDictName(@PathVariable String dictCode,
                              @PathVariable String value){
        String dictName=service.getDictName(dictCode,value);
        return dictName;
    }

    //根据value值查询省市区接口
    @ApiOperation("根据value值查询省市区接口")
    @GetMapping("getDictName/{value}")
    public String getDictName(@PathVariable String value){
        String dictName=service.getDictName("",value);
        return dictName;
    }
}
